package cn.edu.scau.dao;

import cn.edu.scau.entity.DishCalender;
import cn.edu.scau.entity.DishCalenderShow;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
@CacheNamespace
public interface DishCalenderMapper {
	/**
	  * 根据膳食统计编号删除膳食统计信息
	 * @param dishcalenderid
	 * @return
	 */
    @Delete({
        "delete from dishcalender",
        "where dishcalenderID = #{dishcalenderid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer dishcalenderid);

    /**
	  * 全参新增膳食统计信息：不考虑为null情况
     * @param record
     * @return
     */
    @Insert({
        "insert into dishcalender (dishcalenderID, dishID, ",
        "dishcalenderDate, dishcalenderTime, ",
        "dishcalenderAmount)",
        "values (#{dishcalenderid,jdbcType=INTEGER}, #{dishid,jdbcType=INTEGER}, ",
        "#{dishcalenderdate,jdbcType=DATE}, #{dishcalendertime,jdbcType=VARCHAR}, ",
        "#{dishcalenderamount,jdbcType=INTEGER})"
    })
    int insert(DishCalender record);

    /**
	  * 全参新增膳食统计信息：考虑为null情况，如果为空，不向数据库插入数据
     * @param record
     * @return
     */
    @InsertProvider(type=DishCalenderSqlProvider.class, method="insertSelective")
    int insertSelective(DishCalender record);

    /**
	  * 根据膳食统计编号查询统计信息
     * @param dishcalenderid
     * @return
     */
    @Select({
        "select",
        "dishcalenderID, dishID, dishcalenderDate, dishcalenderTime, dishcalenderAmount",
        "from dishcalender",
        "where dishcalenderID = #{dishcalenderid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="dishcalenderID", property="dishcalenderid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="dishID", property="dishid", jdbcType=JdbcType.INTEGER),
        @Result(column="dishcalenderDate", property="dishcalenderdate", jdbcType=JdbcType.DATE),
        @Result(column="dishcalenderTime", property="dishcalendertime", jdbcType=JdbcType.VARCHAR),
        @Result(column="dishcalenderAmount", property="dishcalenderamount", jdbcType=JdbcType.INTEGER)
    })
    DishCalender selectByPrimaryKey(Integer dishcalenderid);

	/**
	  * 连接查询所有膳食信息（包含膳食名称） 
	 * @return
	 */
	@Select({ 
		"select", 
		"dishcalenderID, dishcalender.dishID, dishName ,dishcalenderDate, dishcalenderTime, dishcalenderAmount", 
		"from dishcalender,dish",
		"where dishcalender.dishID = dish.dishID"})
	List<DishCalenderShow> selectAll();

	/**
	  * 根据日期、时间段组合模糊查询
	 * @param dishname
	 * @param dishtype
	 * @param dishfeatures
	 * @return
	 */
   @SelectProvider(type = DishCalenderSqlProvider.class,method = "findByDishcalenderdateDishcalendertime")
   List<DishCalenderShow> findByDishcalenderdateDishcalendertime(@Param("dishcalenderdate")Date dishcalenderdate,@Param("dishcalendertime")String dishcalendertime);
    
    /**
	  * 全参修改膳食统计信息：考虑为null情况，如果为空，不会修改数据库中内容
     * @param record
     * @return
     */
    @UpdateProvider(type=DishCalenderSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(DishCalender record);

    /**
	  * 全参修改膳食统计信息：不考虑为null情况，如果为空，数据库中对应内容将重置为null
     * @param record
     * @return
     */
    @Update({
        "update dishcalender",
        "set dishID = #{dishid,jdbcType=INTEGER},",
          "dishcalenderDate = #{dishcalenderdate,jdbcType=DATE},",
          "dishcalenderTime = #{dishcalendertime,jdbcType=VARCHAR},",
          "dishcalenderAmount = #{dishcalenderamount,jdbcType=INTEGER}",
        "where dishcalenderID = #{dishcalenderid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(DishCalender record);
}